﻿using System;
using System.Data;
using System.Collections.Generic;
using XYW.Common;
using XYW.Model;
namespace XYW.BLL
{
	/// <summary>
	/// Users
	/// </summary>
	public partial class Users
	{
		private readonly XYW.DAL.Users dal=new XYW.DAL.Users();
		public Users()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
			return dal.GetMaxId();
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			return dal.Exists(id);
		}

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(XYW.Model.Users model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(XYW.Model.Users model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			return dal.Delete(id);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			return dal.DeleteList(idlist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public XYW.Model.Users GetModel(int id)
		{
			
			return dal.GetModel(id);
		}
        public XYW.Model.Users GetModel(string userName)
        {

            return dal.GetModel(userName);
        }

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public XYW.Model.Users GetModelByCache(int id)
		{
			
			string CacheKey = "UsersModel-" + id;
			object objModel = XYW.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(id);
					if (objModel != null)
					{
						int ModelCache = XYW.Common.ConfigHelper.GetConfigInt("ModelCache");
						XYW.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (XYW.Model.Users)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<XYW.Model.Users> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<XYW.Model.Users> DataTableToList(DataTable dt)
		{
			List<XYW.Model.Users> modelList = new List<XYW.Model.Users>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				XYW.Model.Users model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new XYW.Model.Users();
					if(dt.Rows[n]["id"]!=null && dt.Rows[n]["id"].ToString()!="")
					{
						model.id=int.Parse(dt.Rows[n]["id"].ToString());
					}
					if(dt.Rows[n]["name"]!=null && dt.Rows[n]["name"].ToString()!="")
					{
					model.name=dt.Rows[n]["name"].ToString();
					}
					if(dt.Rows[n]["sex"]!=null && dt.Rows[n]["sex"].ToString()!="")
					{
					model.sex=dt.Rows[n]["sex"].ToString();
					}
					if(dt.Rows[n]["number"]!=null && dt.Rows[n]["number"].ToString()!="")
					{
					model.number=dt.Rows[n]["number"].ToString();
					}
					if(dt.Rows[n]["passWord"]!=null && dt.Rows[n]["passWord"].ToString()!="")
					{
					model.passWord=dt.Rows[n]["passWord"].ToString();
					}
					if(dt.Rows[n]["classId"]!=null && dt.Rows[n]["classId"].ToString()!="")
					{
						model.classId=int.Parse(dt.Rows[n]["classId"].ToString());
					}
					if(dt.Rows[n]["avatar"]!=null && dt.Rows[n]["avatar"].ToString()!="")
					{
					model.avatar=dt.Rows[n]["avatar"].ToString();
					}
					if(dt.Rows[n]["nickName"]!=null && dt.Rows[n]["nickName"].ToString()!="")
					{
					model.nickName=dt.Rows[n]["nickName"].ToString();
					}
					if(dt.Rows[n]["signature"]!=null && dt.Rows[n]["signature"].ToString()!="")
					{
					model.signature=dt.Rows[n]["signature"].ToString();
					}
					if(dt.Rows[n]["email"]!=null && dt.Rows[n]["email"].ToString()!="")
					{
					model.email=dt.Rows[n]["email"].ToString();
					}
					if(dt.Rows[n]["QQ"]!=null && dt.Rows[n]["QQ"].ToString()!="")
					{
					model.QQ=dt.Rows[n]["QQ"].ToString();
					}
					if(dt.Rows[n]["cellphone"]!=null && dt.Rows[n]["cellphone"].ToString()!="")
					{
					model.cellphone=dt.Rows[n]["cellphone"].ToString();
					}
					if(dt.Rows[n]["address"]!=null && dt.Rows[n]["address"].ToString()!="")
					{
					model.address=dt.Rows[n]["address"].ToString();
					}
					if(dt.Rows[n]["postId"]!=null && dt.Rows[n]["postId"].ToString()!="")
					{
					model.postId=dt.Rows[n]["postId"].ToString();
					}
					if(dt.Rows[n]["workDanwei"]!=null && dt.Rows[n]["workDanwei"].ToString()!="")
					{
					model.workDanwei=dt.Rows[n]["workDanwei"].ToString();
					}
					if(dt.Rows[n]["workZhiwei"]!=null && dt.Rows[n]["workZhiwei"].ToString()!="")
					{
					model.workZhiwei=dt.Rows[n]["workZhiwei"].ToString();
					}
					if(dt.Rows[n]["workZhichen"]!=null && dt.Rows[n]["workZhichen"].ToString()!="")
					{
					model.workZhichen=dt.Rows[n]["workZhichen"].ToString();
					}
					if(dt.Rows[n]["rongYu"]!=null && dt.Rows[n]["rongYu"].ToString()!="")
					{
					model.rongYu=dt.Rows[n]["rongYu"].ToString();
					}
					if(dt.Rows[n]["isSuper"]!=null && dt.Rows[n]["isSuper"].ToString()!="")
					{
						model.isSuper=int.Parse(dt.Rows[n]["isSuper"].ToString());
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

